home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / exampleCode / opengl / GLUT / progs / examples / sphere2.c < prev    next >
C/C++ Source or Header  |  1996-11-11  |  2KB  |  64 lines

  1.  
  2. /* Copyright (c) Mark J. Kilgard, 1994. */
  3.  
  4. /* This program is freely distributable without licensing fees 
  5.    and is provided without guarantee or warrantee expressed or 
  6.    implied. This program is -not- in the public domain. */
  7.  
  8. #include <GL/glut.h>
  9.  
  10. GLfloat light_diffuse[] =
  11. {1.0, 0.0, 0.0, 1.0};
  12. GLfloat light_position[] =
  13. {1.0, 1.0, 1.0, 0.0};
  14. GLUquadricObj *qobj;
  15.  
  16. void 
  17. display(void)
  18. {
  19.   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  20.   glCallList(1);        /* render sphere display list */
  21.   glutSwapBuffers();
  22. }
  23.  
  24. void 
  25. gfxinit(void)
  26. {
  27.   qobj = gluNewQuadric();
  28.   gluQuadricDrawStyle(qobj, GLU_FILL);
  29.   glNewList(1, GL_COMPILE);  /* create sphere display list */
  30.   gluSphere(qobj, /* radius */ 1.0, /* slices */ 20,  /* stacks 
  31.                                                        */ 20);
  32.   glEndList();
  33.   glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
  34.   glLightfv(GL_LIGHT0, GL_POSITION, light_position);
  35.   glEnable(GL_LIGHTING);
  36.   glEnable(GL_LIGHT0);
  37.   glEnable(GL_DEPTH_TEST);
  38.   glMatrixMode(GL_PROJECTION);
  39.   gluPerspective( /* field of view in degree */ 40.0,  /* aspect 
  40.                                                           ratio 
  41.                                                         */ 1.0,
  42.     /* Z near */ 1.0, /* Z far */ 10.0);
  43.   glMatrixMode(GL_MODELVIEW);
  44.   gluLookAt(0.0, 0.0, 5.0,  /* eye is at (0,0,5) */
  45.     0.0, 0.0, 0.0,      /* center is at (0,0,0) */
  46.     0.0, 1.0, 0.);      /* up is in positive Y direction */
  47.   glTranslatef(0.0, 0.0, -1.0);
  48. }
  49.  
  50. int 
  51. main(int argc, char **argv)
  52. {
  53.   glutInit(&argc, argv);
  54.   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  55.   glutCreateWindow("sphere");
  56.   glutDisplayFunc(display);
  57.   gfxinit();
  58.   glutCreateWindow("a second window");
  59.   glutDisplayFunc(display);
  60.   gfxinit();
  61.   glutMainLoop();
  62.   return 0;             /* ANSI C requires main to return int. */
  63. }
  64.